package com.hzqy.service.epg;

import com.hzqy.persistence.dao.epg.AcRecordDao;
import com.hzqy.web.vo.epg.AcRecordVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AcRecordService {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private AcRecordDao acDao;
	public  Map<String,Object> selectAc(AcRecordVo arv, int page, int rows){
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("f_ar_serverid",arv.getF_ar_serverid());
        map.put("f_ar_activityid",arv.getF_ar_activityid());
        map.put("f_ar_phone",arv.getF_ar_phone());
        map.put("f_ar_target", arv.getF_ar_target());
        map.put("f_ar_type", arv.getF_ar_type());
        map.put("beginDate", arv.getBeginDate());
        map.put("endDate", arv.getEndDate());
        Integer rowCount = acDao.selectAcCount(map);
        map.put("total", rowCount);
        if(rowCount>0 && page>0 && rows>0){
            map.put("firstResult",(page-1)*rows);
            map.put("maxResults", rows);
           List<AcRecordVo> list=acDao.selectAcByRequest(map);
            map.put("rows", list);
        }else{
            map.put("rows", new ArrayList<AcRecordVo>());
        }
        return map;
	}
	//添加
	public Map<String, Object> insertRecord(AcRecordVo acBFRecordVo){
		Map<String, Object> map2 = new HashMap<String, Object>();
		int flag = acDao.insertRecord(acBFRecordVo);
		if (flag > 0) {
			map2.put("success", true);
			map2.put("flag", "success");
		}else {
			map2.put("success", false);
			map2.put("flag", "error");
		}
		return map2;
	}
	//修改
	public Map<String, Object> updateRecord(AcRecordVo acBFRecordVo){
		Map<String, Object> map2 = new HashMap<String, Object>();
		int flag = acDao.updateRecord(acBFRecordVo);
		if (flag > 0) {
			map2.put("success", true);
			map2.put("flag", "success");
		}else {
			map2.put("success", false);
			map2.put("flag", "error");
		}
		return map2;
	}
	//删除
	public Map<String, Object> deleteRecord(int f_ar_id){
		Map<String, Object> map2 = new HashMap<String, Object>();
		int flag = acDao.deleteRecord(f_ar_id);
		if (flag > 0) {
			map2.put("success", true);
			map2.put("flag", "success");
		}else {
			map2.put("success", false);
			map2.put("flag", "error");
		}
		return map2;
	}
	
	public Map<String,Object> selectServerList(AcRecordVo acBFRecordVo,int page, int rows){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_ar_activityid", acBFRecordVo.getF_ar_activityid());
		map.put("f_ar_serverid", acBFRecordVo.getF_ar_serverid());
		map.put("type", acBFRecordVo.getType());
		map.put("beginDate", acBFRecordVo.getBeginDate());
        map.put("endDate", acBFRecordVo.getEndDate());
        map.put("f_ar_phone",acBFRecordVo.getF_ar_phone());
		int count = acDao.selectServerCount(map);
		map.put("total", count);
		if(count>0 && page>0 && rows>0){
        	map.put("firstResult",(page-1)*rows);
        	map.put("maxResults", rows);
        	List<AcRecordVo> list = acDao.selectServerList(map);
        	map.put("rows", list);
        }else{
            map.put("rows", new ArrayList<AcRecordVo>());
        }
		return map;
	}
	
	public AcRecordVo selectRecordById(int f_ar_id) {
		return acDao.selectRecordById(f_ar_id);
	}

}
